﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Admin.master" AutoEventWireup="true" CodeBehind="DailyTimeEntry.aspx.cs" Inherits="Legazpi.Payroll.Web.Admin.Payroll.DailyTimeEntry" %>
<asp:Content ID="Content1" ContentPlaceHolderID="headContent" runat="server">
    <script src="<%=ResolveUrl("~/Scripts/jquery.timepicker.min.js")%>" type="text/javascript"></script>
    <link href="<%=ResolveUrl("~/Styles/jquery.timepicker.css")%>" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
    $(document).ready(function () {
        $('#<%=EmployeeName.ClientID %>').autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: '<%=ResolveUrl("~/Webservices/EmployeeWebService.asmx/FetchEmployees")%>',
                    data: "{ 'employeeName': '" + request.term + "' }",
                    dataType: "json",
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    dataFilter: function (data) { return data; },
                    success: function (data) {
                        response($.map(data.d, function (item) {
                            return {
                                label: item.EmployeeName,
                                value: item.EmployeeName,
                                id: item.Id
                            }
                        }))
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(textStatus);
                    }
                });
            },
            minLength: 2,
            select: function (event, ui) {
                var id = ui.item.id;
                var employeeName = ui.item.label;

                $('#<%=EmployeeName.ClientID %>').val(employeeName);
                $('#<%=EmployeeIdHidden.ClientID %>').val(id);
                $('#<%=SearchBtn.ClientID %>').click();
                //window.location = '<%=Request.Path %>?id=' + id;
            }
        });
    });
    $(function () {
        $('.input-long.inputTime').timepicker({
        //'timeFormat': 'H:i'
        });

        $('.input-long.inputTime').on('changeTime', function () {
            //IdentifierName_DayID_EmployeeID
            var arrElement = $(this).attr("id").split('_');
            var dayId = arrElement[1];
            var employeeId = arrElement[2];

            ComputeHoursPerDay(dayId, employeeId);
            ComputeTotalWorkHours(employeeId);
        });

    });
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="leftContent" runat="server">
    <div class="grid_10">                                    
        <%if(IsSuccess) {%>
            <span class="notification n-success"><%=NotifyText %></span>                                                
        <%} %>           
        <%if(IsError) {%>
            <span class="notification n-error"><%=NotifyText %></span>                                                
        <%} %>           
        <div class="bottom-spacing">                
            <!-- Table records filtering -->
            Select Designated Payroll Period: 
            <asp:DropDownList runat="server" ID="PayrollPeriodDdl" CssClass="input-short" 
                AutoPostBack="True" 
                onselectedindexchanged="PayrollPeriodDdl_SelectedIndexChanged">
            </asp:DropDownList>               
        </div> 
    </div>   
            <div class="grid_4">                                
                <div class="module">
                     <h2><span>Daily Time Record Entry</span></h2>
                        
                     <div class="module-body">
                        <p>
                            <label>Employee Name (type in name to search):</label>
                            <asp:TextBox ID="EmployeeName" runat="server" CssClass="input-long"></asp:TextBox>    
                            <asp:HiddenField runat="server" ID="EmployeeIdHidden" Value="0" />   
                            <asp:HiddenField runat="server" ID="DTRIdHidden" Value="0" />   
                            
                            <asp:Button ID="SearchBtn" runat="server" style="display:none"  OnClick="SearchBtn_Click"/> 
                            <hr />                                                                                        
                        </p>                        
                         <asp:Repeater ID="repeaterRecordEntry" runat="server" onitemdatabound="repeaterRecordEntry_ItemDataBound">
                            <HeaderTemplate>
                                <table width="100%" border="0" class="tablesorter">
                                    <thead>
                                        <th width="5%">Day</th>
                                        <th width="20%">In</th>
                                        <th width="20%">Out</th>
                                        <th width="10%">WorkHours</th>                                        
                                        <th>Holiday</th>                                        
                                    </thead>
                                    <tbody>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <tr class="odd">                                                                        
                                    <td>
                                        <asp:Literal runat="server" ID="DayLiteral"></asp:Literal>                                        
                                    </td>                                    
                                    <td><asp:TextBox runat="server" CssClass="input-long inputTime" ID="INtextItem"></asp:TextBox></td>             
                                    <td><asp:TextBox runat="server" CssClass="input-long inputTime" ID="OuttextItem"></asp:TextBox></td>             
                                    <td align="center"><asp:Literal runat="server" ID="WorkHoursLiteral"></asp:Literal></td>     
                                    <td>
                                        <asp:DropDownList ID="HolidayDropdown" runat="server" Width="100%">
                                            <asp:ListItem Text="----" Value="0" /> 
                                            <asp:ListItem Text="LEGAL" Value="1" /> 
                                            <asp:ListItem Text="SPECIAL" Value="2" />                                             
                                       </asp:DropDownList>                                       
                                    </td>                                    
                                </tr>                            
                            </ItemTemplate>
                            <AlternatingItemTemplate>
                                <tr class="even">                                    
                                    <td>
                                        <asp:Literal runat="server" ID="DayLiteral"></asp:Literal>                                        
                                    </td>                                    
                                    <td><asp:TextBox runat="server" CssClass="input-long inputTime" ID="INtextItem"></asp:TextBox></td>             
                                    <td><asp:TextBox runat="server" CssClass="input-long inputTime" ID="OuttextItem"></asp:TextBox></td>             
                                    <td align="center"><asp:Literal runat="server" ID="WorkHoursLiteral"></asp:Literal></td>     
                                    <td>
                                        <asp:DropDownList ID="HolidayDropdown" runat="server" Width="100%">
                                            <asp:ListItem Text="----" Value="0" /> 
                                            <asp:ListItem Text="LEGAL" Value="1" /> 
                                            <asp:ListItem Text="SPECIAL" Value="2" />                                             
                                        </asp:DropDownList>                                       
                                    </td>                                    
                                </tr>                            
                            </AlternatingItemTemplate>
                            <FooterTemplate>
                                    </tbody>
                                </table>
                            </FooterTemplate>
                         </asp:Repeater>   

                            <fieldset>
                                <asp:Button id="SubmitBtn" runat="server" Text="Submit" CssClass="submit-green" 
                                    onclick="SubmitBtn_Click" />                                                                                                            
                                <asp:Button id="CancelBtn" runat="server" Text="Cancel" CssClass="submit-gray" 
                                    onclick="CancelBtn_Click" />                                                                                                            
                            </fieldset>
                        
                        
                     </div> <!-- End .module-body -->
                </div> <!-- End .module -->
                <div style="clear:both;"></div>
            </div>
            <div class="grid_5">      
  
                    <div class="module">
                         <h2><span>Employees Table</span></h2>                     
                         <div class="module-body">            
                            <p>
                                <label>Select Sector:</label>
                                <asp:DropDownList runat="server" ID="SectorFilterDropList" CssClass="input-long" 
                                    AutoPostBack="True" 
                                    onselectedindexchanged="SectorFilterDropList_SelectedIndexChanged" >
                                </asp:DropDownList>                                                          
                            </p>                                                                      
                         <asp:Repeater ID="repeater" runat="server" OnItemCommand="repeater_ItemCommand" onitemdatabound="repeater_ItemDataBound">
                            <HeaderTemplate>
                                <table width="100%" border="0" class="tablesorter">
                                    <thead>
                                        <th>Id</th>                        
                                        <th>Code</th>
                                        <th>Name</th>
                                        <th>Position</th>
                                        <th>WorkHours</th>                                        
                                        <th width="15%"></th>
                                    </thead>
                                    <tbody>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <tr class="odd">                                    
                                    <td><%# Eval("Id")%></td>                                        
                                    <td><asp:Literal runat="server" ID="CodeLiteral"></asp:Literal></td>                                    
                                    <td><asp:Literal runat="server" ID="NameLiteral"></asp:Literal></td>             
                                    <td><asp:Literal runat="server" ID="PositionLiteral"></asp:Literal></td>                                         
                                    <td><asp:Literal runat="server" ID="WorkHoursLiteral"></asp:Literal></td>                                    
                                    <td>                                        
                                        <asp:ImageButton ID="SaveLinkBtn" runat="server" ImageUrl="/images/pencil.gif" Width="16" Height="16" AlternateText="save" CommandName="update" CommandArgument=<%# Eval("Id")%> />                                        
                                    </td>
                                </tr>                            
                            </ItemTemplate>
                            <AlternatingItemTemplate>
                                <tr class="even">                                    
                                    <td><%# Eval("Id")%></td>                                        
                                    <td><asp:Literal runat="server" ID="CodeLiteral"></asp:Literal></td>                                    
                                    <td><asp:Literal runat="server" ID="NameLiteral"></asp:Literal></td>             
                                    <td><asp:Literal runat="server" ID="PositionLiteral"></asp:Literal></td>                                         
                                    <td><asp:Literal runat="server" ID="WorkHoursLiteral"></asp:Literal></td>                                    
                                    <td>                                        
                                        <asp:ImageButton ID="SaveLinkBtn" runat="server" ImageUrl="/images/pencil.gif" Width="16" Height="16" AlternateText="save" CommandName="update" CommandArgument=<%# Eval("Id")%> />                                        
                                    </td>
                                </tr>                            
                            </AlternatingItemTemplate>
                            <FooterTemplate>
                                    </tbody>
                                </table>
                            </FooterTemplate>
                         </asp:Repeater>                            
                         </div> <!-- End .module-body -->

                    </div>  <!-- End .module -->        		   
                                                            
            </div>
</asp:Content>
